package pl.edu.agh.iosr.gamblingzone.utils;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;

public class HashGenerator {
	private static Random rand;	
	
	public static String generatePassword(){
		return generate(10);
	}
	
	public static String generateVoucherHash() {
		StringBuffer sb = new StringBuffer(generate(6));
		
		for(int i = 0; i < 3; i++) {
			sb.append("-");
			sb.append(generate(6));
		}
		
		return sb.toString();
	}
	
	private static String generate(int size) {
		
		try {
			rand = SecureRandom.getInstance("SHA1PRNG");
		} catch (NoSuchAlgorithmException e) {
			rand = new Random();
		}		
			
		int length = rand.nextInt(size) + 6;
		char[] password = new char[length];

		for (int x = 0; x < length; x++) {
			int randDecimalAsciiVal = rand.nextInt(93) + 33;
			password[x] = (char) randDecimalAsciiVal;
		}

		return String.valueOf(password);
	}
}
